yjx.service('imService',['$rootScope','$timeout',function($rootScope,$timeout){
    return {
        /*设置自己资料*/
        setProfilePortrait:function(){
            console.log($rootScope.user.avatar);
            console.log($rootScope.user.nickname);
           var  options = {
               "ProfileItem":
                   [
                       {
                           "Tag":"Tag_Profile_IM_Nick",
                           "Value":$rootScope.user?$rootScope.user.nickname:'',
                       },
                       {
                           "Tag":"Tag_Profile_IM_Image",
                           "Value":$rootScope.user?$rootScope.user.avatar:'',
                       }
                   ]
            }
            webim.setProfilePortrait(
                options,
                function (resp) {
                    //alert('设置个人资料成功');
                },
                function (err) {
                    //alert(err.ErrorInfo);
                }
            );
        },

        /*获取对方资料*/
        getProfile:function(){
           var options= {
                "To_Account":[$rootScope.service.userId.toString()],
                "TagList":
                [
                    "Tag_Profile_IM_Nick",
                    "Tag_Profile_IM_Image",
                ]
            }
            webim.getProfilePortrait(
                options,
                function (resp) {
                    if (resp.UserProfileItem && resp.UserProfileItem.length > 0) {
                        for (var i in resp.UserProfileItem) {
                            var nick,image;
                            for (var j in resp.UserProfileItem[i].ProfileItem) {
                                switch (resp.UserProfileItem[i].ProfileItem[j].Tag) {
                                    case 'Tag_Profile_IM_Nick':
                                        nick = resp.UserProfileItem[i].ProfileItem[j].Value;
                                        break;
                                    case 'Tag_Profile_IM_Image':
                                        image = resp.UserProfileItem[i].ProfileItem[j].Value;
                                        break;
                                }
                            }
                            $timeout(function(){
                                $rootScope.service.nickname = nick;
                                $rootScope.service.avatar = image;
                                //console.log( $rootScope.service.nickname)
                                console.log( $rootScope.service.avatar)
                            })

                        }
                    }
                },
                function (err) {
                    //alert(err.ErrorInfo);
                }
            );
        }



    }
}])

/*
* 登录
* identifier======================userId
* UserSig
* */